<html>
  <head>
    <title>Line Chart</title>
    <script type="text/javascript" src="../../protovis.js"></script>
  </head>
  <body>
    <script type="text/javascript+protovis">

var data = pv.range(0, 10, .1).map(function(x) {
        return {x: x, y: Math.sin(x) + Math.random() * .5 + 2};
      });

var w = 400,
    h = 200,
    x = pv.Scale.linear(data, function(d) d.x).range(0, w),
    y = pv.Scale.linear(0, 4).range(0, h);

var vis = new pv.Panel()
    .width(w)
    .height(h)
    .bottom(20)
    .left(20)
    .right(10)
    .top(5)
    .fillStyle("#fff")
    .event("mousemove", pv.Behavior.point(Infinity).collapse("y"));

vis.add(pv.Rule)
    .data(x.ticks())
    .visible(function(d) d > 0)
    .left(x)
    .strokeStyle("#eee")
  .anchor("bottom").add(pv.Label)
    .text(function(d) d.toFixed());

vis.add(pv.Rule)
    .data(y.ticks())
    .visible(function() !(this.index % 2))
    .bottom(y)
    .strokeStyle(function(d) d ? "#eee" : "#000")
  .anchor("left").add(pv.Label)
    .text(function(d) d.toFixed(1));

vis.add(pv.Line)
    .def("active", -1)
    .data(data)
    .left(function(d) x(d.x))
    .bottom(function(d) y(d.y))
    .lineWidth(3)
    .event("point", function() this.active(this.index).parent)
    .event("unpoint", function() this.active(-1).parent)
  .add(pv.Dot)
    .fillStyle("white")
    .visible(function() this.proto.active() == this.index)
  .anchor("right").add(pv.Label)
    .text(function(d) d.y.toFixed(2));

vis.render();

    </script>
  </body>
</html>
